﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using TableTop.DataManagement.IO;
using TableTop.Presentation.Win32;
using TableTop.DataManagement.Addon;

namespace TableTop.Presentation
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App 
        : Application
    {

        internal AddonManager Addons
        {
            get;
            private set;
        }

        internal Storage DataStorage
        {
            get;
            private set;
        }

        internal ApplicationPagesContainer ApplicationPages
        {
            get;
            private set;
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.InitializeWin32();
            this.InitializePresentation();
        }

        private void Application_Exit(object sender, ExitEventArgs e)
        {
            this.DisposeWin32();
        }

        private void InitializeWin32()
        {
            UrlMon.InternetSetFeatureEnabled(UrlMon.InternetFeaturelist.DISABLE_NAVIGATION_SOUNDS, 
                                             UrlMon.SetFeatureOn.PROCESS, 
                                             true);
        }

        private void InitializePresentation()
        {
            this.ApplicationPages = new ApplicationPagesContainer();
            this.Addons = new AddonManager();
            this.DataStorage = new Storage();
        }

        private void DisposeWin32()
        {
            if (UrlMon.IsInternetSetFeatureEnabled(UrlMon.InternetFeaturelist.DISABLE_NAVIGATION_SOUNDS, 
                                                   UrlMon.SetFeatureOn.PROCESS) == true)
                UrlMon.InternetSetFeatureEnabled(UrlMon.InternetFeaturelist.DISABLE_NAVIGATION_SOUNDS,
                                             UrlMon.SetFeatureOn.PROCESS,
                                             false);
        }
    }
}
